package com.jj.core.client.impl;

import com.jj.core.client.Client;
import com.jj.message.battle.UserMessage;
import com.jj.net.Context;
import com.jj.net.kcp.KcpChannelManager;
import com.jj.net.tcp.TcpAccepterManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Copyrights: QidianGroup@JJ
 *
 * @author: LuHan
 * @date: 2018/1/15, 13:34
 */
public class ClientImpl implements Client{
    private static Logger logger = LoggerFactory.getLogger(ClientImpl.class);

    private KcpChannelManager kcpChannelManager;

    private TcpAccepterManager tcpAccepterManager;

    private Context tcpContext;

    private Context udpContext;

    private Long uid;

    public ClientImpl(KcpChannelManager kcpChannelManager, TcpAccepterManager tcpAccepterManager, Long uid) {
        this.kcpChannelManager = kcpChannelManager;
        this.tcpAccepterManager = tcpAccepterManager;
        this.uid = uid;
    }

    public Context getTcpContext() {
        return tcpContext;
    }

    public void setTcpContext(Context tcpContext) {
        this.tcpContext = tcpContext;
    }

    public Context getUdpContext() {
        return udpContext;
    }

    public void setUdpContext(Context udpContext) {
        this.udpContext = udpContext;
    }

    public Long getUid() {
        return uid;
    }

    @Override
    public void sendKcp(UserMessage message) {
        Context context = kcpChannelManager.getContextByUid(uid);
        context.send(message);
        logger.debug("sendKcp {}", message);
    }

    @Override
    public void sendTcp(UserMessage userMessage) {
        tcpContext.send(userMessage);
    }
}
